﻿using Iworld.Administrator.Model;
using Iworld.Administrator.Service.Export;
using Iworld.basis.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Iworld.Administrator.Service.Import
{
    /// <summary>
    /// 获取管理员用户组的数据集
    /// </summary>
    [DataContract]
    public class GetAdministratorGroupsImport : GetPageListCheckAdministratorImportBase
    {

        /// <summary>
        /// 关键字
        /// </summary>
        [DataMember]
        public string Keyword { set; get; }

       public PageResult<AdministratorGroupExport> GetAdministratorGroups(IModelToDbContextOfAdministrator db)
       {
           int pageSize = 10;
           int startRow = pageSize * (this.PageIndex - 1);
           IQueryable<AdministratorGroup> temp = db.AdministratorGroups;
           if(Keyword!=null)
           {
               temp = temp.Where(x=>x.Name.Contains(Keyword));
           }
           int totalCount = temp.Count();
           var list = temp.OrderByDescending(x => x.Id).Skip(startRow).Take(pageSize).ToList().ConvertAll(x =>
           {
               return new AdministratorGroupExport(x);
           });

           return new PageResult<AdministratorGroupExport>(this.PageIndex, totalCount, pageSize, list); ;
       }
    }
}
